/**
 * @file 代理类
 * @module libs/proxy
 * @author 月落 <yueluo.yang@qq.com>
 */

/**
 * @description 代理 Page
 * @param {store} $store - 数据源
 * @returns {function}
 */
export const createPageProxy = ($store) => {
  return function (options) {
    
    options.setData = function (data, callback = () => {}) {
      const $datas = Object.keys(data).filter(item => /^\$/.test(item));
      $datas.forEach(key => {
        $store.commit('changeState', {
          [key.substr(1)]: data[key]
        });
      });
      this.__proto__.__proto__.setData.call(this, data, callback);
    };

    Page.call(null, options);
  }
}